// ==UserScript==
// @name         e-cscec AutoClick
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://e-cscec.zhixueyun.com/*
// @icon         https://e-cscec.zhixueyun.com/default/M00/0B/FB/Ci7mTV1klzKAO3T0AAAWfOlaVdY588.png
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    function play_video() {
        const vjs_play_controls = document.getElementsByClassName("vjs-play-control vjs-control vjs-button vjs-paused");
        if(vjs_play_controls) {
            console.log("The video was paused, click start");
            vjs_play_controls[0].click();
        }
    }

    function study_status() {
        const section_arrows=document.getElementsByClassName("section-arrow");
        const chapter_list_box=section_arrows.getElementsByClassName("chapter-list-box required focus ");
        const status=section_arrows.getElementsByClassName("item pointer");
    }

    function loop() {
        press_ok();
    }

    function press_ok() {
        const btn_ok = document.querySelector('#D212btn-ok');
        if(btn_ok == null) {
            //console.log("It havn't found the ok btn");
            return;
        }
        const alerts = document.getElementsByClassName("alert-shadow");
        var hidden_or_display = "block";
        if(alerts) {
            hidden_or_display = alerts[0].style.display;
            //console.log("alerts.style.display:"+hidden_or_display);
            if (hidden_or_display == "") {
                hidden_or_display = "block";
            }
        }
        //console.log("hidden_or_display : "+hidden_or_display);
        if(hidden_or_display == "block" ) {
            console.log("btn ok ...begin");
            btn_ok.click();
            console.log("btn ok ...end");
        }else {
            //console.log("btn ok not available yet, waiting.");
        }
    }

   //time以毫秒为单位
    let time=5000;
    setTimeout(() => {
        play_video()
    },time);

    setInterval(loop, 5000);
})();
